﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using YGWebMobileApi.Data;
using OneMile.DAL;
using OneMile.Common;

namespace YGWebMobileApi.APIs
{
     [MobileAPI(Code = "MS0004", Name = "商家检查是否有新订单")]
    public class SCheckNewOrder:BaseAPI,IProcessMessage
    {
        private DALSOrder dalShopOrder;
        protected DALSOrder DalShopOrder
        {
            get
            {
                if (dalShopOrder == null)
                {
                    dalShopOrder = DALFactory.getInstance().CreateSOrderDAL();
                }
                return dalShopOrder;
            }
        }
        #region IProcessMessage 成员

        public MobileRspMsg ProcessMessage(MobileReqMsg reqMsg)
        {
            try
            {
                MobileRspMsg rspMsg = new MobileRspMsg(reqMsg);

                string ShopId = reqMsg.Body.GetFieldValue("ShopId");
                string orderNumber= reqMsg.Body.GetFieldValue("OrderNumber");
                if (String.IsNullOrEmpty(ShopId)||String.IsNullOrEmpty(orderNumber))
                {
                    rspMsg.Head.RspCode = MessageCode.Paramter_Empty.Code;
                    rspMsg.Head.RspMsg = MessageCode.Paramter_Empty.Msg;
                    return rspMsg;
                }

                Guid guid = new Guid(ShopId);
                bool hasOrder = DalShopOrder.HasNewOrder(orderNumber, guid);
      
                rspMsg.Body.AddField("HasNewOrder",hasOrder.TString().ToLower());

                rspMsg.Head.RspCode = MessageCode.Success.Code;
                rspMsg.Head.RspMsg = MessageCode.Success.Msg;

                return rspMsg;
            }
            catch (Exception e)
            {
                ErrorLogWriter.Write("ShopCheckNewOrder" + e.Message);
                throw e;
            }
        }

        #endregion
    }
}